package com.tz.service.impl;

import com.tz.entity.Research;
import com.tz.entity.ResearchTemplate;
import com.tz.mapper.ResearchMapper;
import com.tz.service.ResearchService;
import com.tz.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by 侯畅畅 on 2018/1/3.
 */
@Service
@Transactional
public class ResearchServiceImpl implements ResearchService {
    @Autowired
    ResearchMapper researchMapper;

    @Override
    public void addResearch(Research research, ResearchTemplate researchTemplate) {
        researchMapper.insertResearch(research, researchTemplate);
    }

    @Override
    public void alterResearch(Research research) {

        researchMapper.updateResearch(research);
    }

    @Override
    public List<Research> findAllResearch(Long researchid) {
        return researchMapper.selectAllResearch(researchid);
    }

    @Override
    public Research findById(Long researchid) {
        return researchMapper.findById(researchid);
    }

    @Override
    public void removeResearch(Long id) {
        researchMapper.deleteResearch(id);
    }

    @Override
    public PageBean<Research> findResearchsByPage(Integer pageNow, Integer pageSize, int state, String string) {
        PageBean<Research> pageBean = new PageBean<>();
        pageBean.setPageNow(pageNow);
        pageBean.setPageSize(pageSize);
        pageBean.setTotalRecords(researchMapper.countResearch(state));
        pageBean.setPageDatas(researchMapper.selectResearchByCondition(pageNow, pageSize, state, string));
        //返回数据
        return pageBean;
    }

    @Override
    public Long getTempIDbyResearchID(Long id) {
        return researchMapper.selectTemp(id);
    }
}